package base;
import java.sql.*;


public class Mantencion {
  conectate con;
  
  public Mantencion (){
    con = new conectate();
  } 
  
  
   public void Mantencion(String sec,String des,String res,String ent,String fol){
       try {            
            PreparedStatement pstm = con.getConnection().prepareStatement("insert into " + 
                    "mantencion(secuencia,descripcion,resepcion,entrega.folio) " +
                    " values(?,?,?,?,?)");            
            pstm.setString(1, sec); 
            pstm.setString(2, des);
            pstm.setString(3, res);
            pstm.setString(4, ent);
            pstm.setString(5, fol);
            pstm.execute();
            pstm.close();            
         }catch(SQLException e){
         System.out.println(e);
      }
   }

     public void updateMantencion(String sec,String des,String res,String ent,String fol){
       try {            
            PreparedStatement pstm = con.getConnection().prepareStatement("update Mantencion " +
            "set secuencia = ? ," +
            "descripcion = ? ," +
            "resepcion = ? ," +      
            "entrega = ? ," +  
            "folio = ? ," +        
            "where id = ? ");            
            pstm.setString(1, sec);                   
            pstm.setString(2, des);
            pstm.setString(3, res);
            pstm.setString(4, ent);
            pstm.setString(5, fol);
            pstm.execute();
            pstm.close();            
         }catch(SQLException e){
         System.out.println(e);
      }
   }
   
   public void deleteregistro(String cod){  
            try {                
                PreparedStatement pstm = con.getConnection().prepareStatement("delete from mantencion where id = ?");            
                pstm.setString(1, cod);                   
                pstm.execute();
                pstm.close();            
            }catch(SQLException e){
            System.out.println(e);
            }            
   }


    
 
 public Object [][] getDatos(){
      int registros = 0;
      
      try{         
         PreparedStatement pstm = con.getConnection().prepareStatement("SELECT count(1) as total FROM Mantencion ");
         ResultSet res = pstm.executeQuery();
         res.next();
         registros = res.getInt("total");
         res.close();
      }catch(SQLException e){
         System.out.println(e);
      }
      
    Object[][] data = new String[registros][5];  
    
      try{    
         PreparedStatement pstm = con.getConnection().prepareStatement("SELECT " +
            " secuencia,descripcion,resepcion,entrega,folio " +
            " FROM mantencion" +
            " ORDER BY id ");
         ResultSet res = pstm.executeQuery();
         int i = 0;
         while(res.next()){
            String estsec = res.getString("secuencia");
            String estdes = res.getString("descripcion");
            String estres = res.getString("resepcion");
            String estent = res.getString("entrega");
            String estfol = res.getString("folio");
            data[i][0] = estsec;            
            data[i][1] = estdes; 
            data[i][1] = estres;
            data[i][1] = estent;
            data[i][1] = estfol;
            i++;
         }
         res.close();
          }catch(SQLException e){
         System.out.println(e);
    }
    return data;
 }    
}